<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>药品信息管理</title>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <script src="../../layui/layui.js"></script>
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <!---头部导航栏-->
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs layui-bg-black"> <img src="//unpkg.com/outeres@0.0.10/img/layui/icon-v2.png" class="layui-nav-img">小药店管理系统</div>
        <!-- 头部区域（可配合layui 已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <!-- 移动端显示 -->
            <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
                <i class="layui-icon layui-icon-spread-left"></i>
            </li>
            <li class="layui-nav-item layui-hide-xs"><a href="javascript:;">前台页面</a></li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
                <a href="javascript:;">
                    <img src="" class="layui-nav-img" >
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="javascript:;">文件</a></dd>
                    <dd><a href="javascript:;">设置</a></dd>
                    <dd><a href="javascript:;">登出</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
                <a href="javascript:;">
                    <i class="layui-icon layui-icon-more-vertical"></i>
                </a>
            </li>
        </ul>
    </div>

    <!---菜单导航栏-->
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">采购管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="./gongyingshangxinxi.html">供应商信息管理</a></dd>
                        <dd><a href="javascript:;">药品信息管理</a></dd>
                        <dd><a href="./caigoudan.html">采购单添加</a></dd>
                        <dd><a href="./PurchaseDetail">采购明细管理</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">销售管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="../salemanage/addsale.html">销售单添加管理</a></dd>
                        <dd><a href="../salemanage/saledetailmanage.html">销售明细管理</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">药店统计管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="../medicalstatisticmanage/Inboundstatistic.html">入库统计</a></dd>
                        <dd><a href="../medicalstatisticmanage/salestatistic.html">销售统计</a></dd>
                        <dd><a href="../medicalstatisticmanage/invebtoryinquuiry">库存查询</a></dd>
                    </dl>
                </li>

                <li class="layui-nav-item">
                    <a href="javascript:;">人事管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="../peoplemanage/addpeople.html">员工添加</a></dd>
                        <dd><a href="../peoplemanage/managepeople.html">员工管理</a></dd>
                    </dl>
                </li>

                <li class="layui-nav-item">
                    <a href="javascript:;">打印管理</a>
                    <dl class="layui-nav-child">
                        <dd class="layui-this"><a href="../print/enterlibrary">入库单</a></dd>
                        <dd ><a href="../print/exitlibrary.html">出库单</a></dd>
                    </dl>
                </li>

                <li class="layui-nav-item">
                    <a href="javascript:;">系统管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="../systemmanage/updatepassword.html">修改密码</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>

    <!---内容-->
    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">
            <button class="layui-btn" id="addDrugBtn">添加药品</button>
<!--            &lt;!&ndash; 添加药品表单 &ndash;&gt;-->
<!--            <div id="addDrugForm" style="display: none;">-->
<!--                <form class="layui-form" action="">-->
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">药品名称</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="name" required  lay-verify="required" placeholder="请输入药品名称" autocomplete="off" class="layui-input">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">供应商</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="lianxiren" required  lay-verify="required" placeholder="请输入供应商" autocomplete="off" class="layui-input">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">单位</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="dianhua" required  lay-verify="required" placeholder="请输入单位" autocomplete="off" class="layui-input">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">保质期</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="youbian" required  lay-verify="required" placeholder="请输入保质期" autocomplete="off" class="layui-input">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">备注</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="beizhu" required  lay-verify="required" placeholder="请输入备注" autocomplete="off" class="layui-input">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-form-item">-->
<!--                        <div class="layui-input-block">-->
<!--                            <button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>-->
<!--                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </form>-->
<!--            </div>-->
            <table class="layui-table" lay-data="{height: 'full-150', url:'/drug/show', page:true}" id="ID-table-demo-init1">
                <thead>
                <tr>
                    <th lay-data="{field:'name'}">药品名称</th>
                    <th lay-data="{field:'lianxiren'}">供应商</th>
                    <th lay-data="{field:'dianhua'}">单位</th>
                    <th lay-data="{field:'youbian'}">保质期</th>
                    <th lay-data="{field:'beizhu'}">备注</th>
                    <th lay-data="{toolbar: '#delete_operation'}">操作</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>

    <!---底部导航栏-->
    <div class="layui-footer">
        <!-- 底部固定区域 -->
        底部固定区域
    </div>
</div>

<script src="../../layui/layui.js"></script>
<script type="text/html" id="delete_operation">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
    layui.use(['layer', 'form', 'table'], function(){
        var $ = layui.$;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table; // 确保 table 模块被正确赋值
        // 监听删除操作
        table.on('tool(ID-table-demo-init1)', function(obj){
            var data = obj.data; // 获取当前行数据
            var id = data.id; // 获取药品ID

            layer.confirm('真的删除行么', function(index){
                $.ajax({
                    url: '/drug/del',
                    type: 'POST',
                    data: {id: id}, // 确保传递 id 参数
                    success: function(res){
                        if(res.code === 0){
                            layer.msg('删除成功');
                            obj.del(); // 删除对应行（tr）的DOM结构
                        } else {
                            layer.msg('删除失败');
                        }
                    },
                    error: function(xhr, status, error){
                        console.error('删除请求失败:', xhr.responseText);
                        layer.msg('删除请求失败');
                    }
                });
                layer.close(index);
            });
        });
    });
});
</script>
</body>
</html>